let db = require('../db/index')

exports.addApply = (req, res) => {
  const info = req.body
  const sql = 'insert into apply (userId,username,email,permission) value (?,?,?,?)'

  db.query(sql, [info.id, info.username, info.email, info.permission], (err, data) => {
    if (err) {
      return res.send('添加失败' + err.message)
    }
    res.send({
      code: 20000,
      data: '添加成功'
    })
  })
}

exports.getApplyList = (req, res) => {
  const sql = 'select * from apply'
  db.query(sql, (err, data) => {
    if (err) {
      return res.send('获取失败' + err.message)
    }
    res.send({
      code: 20000,
      data: data
    })
  })
}

exports.deleteApply = (req, res) => {
  const id = req.params.id
  const sql = 'delete from apply where userId = ?'
  db.query(sql, id, (err, data) => {
    if (err) {
      return res.send('删除失败' + err.message)
    }
    res.send({
      code: 20000,
      data: '删除成功'
    })
  })
}